<template>
  <div class="container">
    <el-dialog :visible.sync="closeFlag" width="30%" title="题目审核" @close="handleClose">
      <el-form :model="form" :rules="rules" ref="refForm">
        <el-form-item prop="chkState">
          <el-radio-group v-model="form.chkState">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item prop="chkRemarks">
          <el-input type="textarea" v-model="form.chkRemarks" placeholder="请输入审核意见"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="btnOk">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      rules: {
        chkRemarks: [
          { required: true, message: '请输入审核意见', trigger: 'blur' },
          { min: 5, max: 100, message: '长度在 5 到 100 个字符', trigger: 'blur' }
        ]
      },
      form: {
        chkState: 1,
        chkRemarks: ''
      }
    }
  },
  computed: {
    closeFlag: {
      get () {
        return this.dialogFlag
      },
      set (value) {
        value = this.dialogFlag
      }
    }
  },
  props: {
    dialogFlag: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 点击确定按钮
    btnOk () {
      this.$refs.refForm.validate((valid) => {
        if (valid) {
          this.$emit('checkContent', this.form)
        } else {
          console.log('请填写')
          return false
        }
      })
    },
    // 对话框关闭前回调
    handleClose () {
      this.$refs.refForm.resetFields()
      this.$emit('update:dialogFlag', false)
    }
  }
}
</script>

<style scoped lang='less'>
</style>
